//
//  CTRemindView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/4/21.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTRemindView.h"
#import "CTDebugManager.h"
#import "CTTextManager.h"
#import "CTAppLanguage.h"
#import "UIViewAdditions.h"
#import "CTAppLanguage.h"

@implementation CTRemindView


- (void)dealloc
{
    [CTDebugManager showDebugLogInfo:@"dealloc : CTRemindView Is Removed!!!"];
}


- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.frame = CGRectMake(0, 0, 50, 25);
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}



-(void)showRemindViewWithRemindWord:(NSString *)remindStr
{
    [self showRemindViewOn:nil withRemindWord:remindStr];
}

-(void)showRemindViewOn:(UIView *)view
         withRemindWord:(NSString *)remindStr
{
    
    if ([[CTTextManager shareInstance] isBlankString:remindStr] == YES) {
        return;
    }
    
    
    UILabel * remindLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    [remindLabel setNumberOfLines:0];
    remindLabel.backgroundColor = [UIColor clearColor];
    remindLabel.textColor = [UIColor whiteColor];
    remindLabel.textAlignment = NSTextAlignmentCenter;
    remindLabel.text = remindStr;
    UIFont *font = [UIFont fontWithName:@"Arial" size:17];
    CGSize size = CGSizeMake(200,100);
    CGSize labelsize = [remindStr sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
    [remindLabel setFrame:CGRectMake(0,0, labelsize.width+30, labelsize.height+15)];

    self.bounds = remindLabel.bounds;
    
    UIView * shadowView = [[UIView alloc] initWithFrame:self.bounds];
    shadowView.alpha = 0.7;
    shadowView.layer.cornerRadius = 3.0;
    shadowView.backgroundColor = [UIColor blackColor];
    [self addSubview:shadowView];
    
    
    
    [self addSubview:remindLabel];
    if (view == nil) {
        [self.window addSubview:self];
        self.center = self.window.center;
    }
    else
    {
        [view addSubview:self];
        self.center = view.center;
    }
    
    [self performSelector:@selector(remove) withObject:nil afterDelay:1.5];
}

-(void)showRemindViewForSaveOn:(UIView *)view
{
    if ( view == nil) {
    return;
    }
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 135, 135)];
    imageView.image = [UIImage imageNamed:@"Edit_save_ok"];
    imageView.center = self.center;
    [self addSubview:imageView];
    
    UILabel *saveLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.origin.x, imageView.origin.y+92, imageView.width, 15)];
    
    saveLabel.font = [UIFont fontWithName:@"Arial" size:13];
    saveLabel.textAlignment = NSTextAlignmentCenter;
    saveLabel.text = [CTAppLanguage localizedStringForKey:@"remindView_save" withValue:nil withTable:@"Language"];
    saveLabel.textColor =[UIColor colorWithRed:113/255.0 green:113/255.0 blue:113/255.0 alpha:1.0];
    [self addSubview:saveLabel];
    
    [view addSubview:self];
    self.center = view.center;
    
    [self performSelector:@selector(remove) withObject:nil afterDelay:1.5];
}
-(void)showRemindViewForCollectionOn:(UIView *)view
{
    if ( view == nil) {
        return;
    }
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 135, 135)];
    imageView.image = [UIImage imageNamed:@"Col_Success_bg"];
    imageView.center = self.center;
    [self addSubview:imageView];

    UILabel *saveLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.origin.x, imageView.origin.y+92, imageView.width, 15)];
    saveLabel.font = [UIFont fontWithName:@"Arial" size:13];
    saveLabel.textAlignment = NSTextAlignmentCenter;
    saveLabel.text = [CTAppLanguage localizedStringForKey:@"remindView_collection" withValue:nil withTable:@"Language"];
    saveLabel.textColor = [UIColor colorWithRed:113/255.0 green:113/255.0 blue:113/255.0 alpha:1.0];
    [self addSubview:saveLabel];
    [view addSubview:self];
    self.center = view.center;
    
    [self performSelector:@selector(remove) withObject:nil afterDelay:1.5];
}
-(void)remove
{
    [self removeFromSuperview];
}


@end
